import axios from 'axios'
import Qs from 'qs'
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8';
// 创建axios实例
const request = axios.create({
  // axios中请求配置有baseURL选项，表示请求URL公共部分
  baseURL: "http://localhost:9093/",
  // 超时
  timeout: 10000
});

/*TODo 注意,如果是psot请求,不加params  ,get请求需要加上*/

request.interceptors.request.use(
  config => {
    /*if (getToken()) {
      config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
    }*/
    //获取登录成功后返回的token
    //添加token,
    config.headers['Authorization'] = window.localStorage.getItem("token"); // 让每个请求携带自定义token 请根据实际情况自行修改
    return config
  },
  error => {
    console.log(error);
    Promise.reject(error)
  }
);


// gateway路由分页
export function routePage(current, size) {
  const data = {
    "current":current,
    "size":size
  };
  return request({
    url: '/web/route/page',
    method: 'get',
    data:data
  })
}

// 路由刷新
export function refresh() {
  return request({
    url: '/web/route/refresh',
    method: 'get',
  })
}


// 路由刷新
export function currentRoutes() {
  return request({
    url: '/actuator/gateway/routes',
    method: 'get',
  })
}


export function securityLogin(username, password) {
  const data = {
    "username":username,
    "password":password
  };
  console.log("登录的账号:", username);
  return request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    },
    url: '/login',
    method: 'post',
    data:Qs.stringify(data),
  })
}


